package com.yuexun.dhdoctor.module.main.presenter.impl;

import android.util.Log;

import com.yuexun.dhdoctor.module.main.bean.UpdateBean;
import com.yuexun.dhdoctor.module.main.model.IUpdateModel;
import com.yuexun.dhdoctor.module.main.presenter.IUpdatePresenter;
import com.yuexun.dhdoctor.module.main.ui.view.IUpdateView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2016/9/20.
 */
public class UpdatePresenter implements IUpdatePresenter {
    private IUpdateView view;
    private IUpdateModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public UpdatePresenter(IUpdateModel model, IUpdateView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void update() {
        model.update()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<UpdateBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("jx",e.toString());
                        view.showUpdateError();
                    }

                    @Override
                    public void onNext(UpdateBean updateBean) {
                        view.showUpdateInfo(updateBean);
                    }
                });
    }
}
